﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

namespace TVC
{
    [Serializable()]
    public class TypeCategoryNode : CategoryNode
    {
        private TreeNodeCollection mobjNodes = null;
        private Type mobjType = null;
        private TreeNode mobjNode = null;

        //private object _ObTag = this;Folder.gif

        public TypeCategoryNode(CategoryNode objParent, TreeNodeCollection objParebtNodes, string strLabel, string module, Type objType, string address, string language)
            : this(objParent, objParebtNodes, strLabel, module, objType, "", address, language)
        {
        }

        public TypeCategoryNode(CategoryNode objParent, TreeNodeCollection objParebtNodes, string strLabel, string module, Type objType, string strIcon, string address, string language)
            : base(objParent, strLabel, address, language)
        {
            //Dictionary<int, string> myData = new Dictionary<int, string>();
            //myData.Add(1, NoteValue);
            mobjNode = new TreeNode(strLabel);
            mobjNode.Name = module;
            mobjNode.Text = clsConfigurarion.GetLabel(objType.ToString(), "", strLabel, language);
            //mobjNode.Image = new IconResourceHandle(strIcon);
            //mobjNode.ExpandedImage = new IconResourceHandle("Interface.gif");
            mobjNode.Tag = this;
            //mobjNode. = strIcon;
            mobjNode.IsExpanded = false;
            objParebtNodes.Add(mobjNode);
            mobjNodes = mobjNode.Nodes;
            mobjType = objType;
        }

        public override Control GetCategoryInstance(MainForm main = null)
        {
            Control result = Activator.CreateInstance(this.mobjType) as Control;
            if (result is Modules.ModuleParent) ((Modules.ModuleParent)result).MainForm = main;
            return result;
        }

        public override TreeNodeCollection Nodes
        {
            get
            {
                return mobjNodes;
            }
        }

        public override void SetDefault()
        {
            mobjNode.TreeView.SelectedNode = mobjNode;
            Expand(mobjNode);
        }

        public override string Text
        {
            get
            {
                return mobjNode == null ? "Node" : mobjNode.Text;
            }
            set { if (mobjNode != null) mobjNode.Text = value; }
        }

    }

}
